#include <iostream>

using namespace std;

struct student
{
    char name[10];
    int a, b, c, sum;
};

int compare(student *a, student *b);

int main()
{
    int t;
    cin >> t;
    student *stu = new student[t];
    for (int i = 0; i < t; i++)
    {
        cin >> stu[i].name >> stu[i].a >> stu[i].b >> stu[i].c;
        stu[i].sum = stu[i].a + stu[i].b + stu[i].c;
    }
    for (int i = 0; i < t; i++)
    {
        for (int j = i + 1; j < t; j++)
        {
            if (compare(stu + i, stu + j))
            {
                if (stu[i].name > stu[j].name)
                {
                    cout << stu[j].name << " " << stu[i].name << endl;
                }
                else
                {
                    cout << stu[i].name << " " << stu[j].name << endl;
                }
            }
        }
    }

    return 0;
}

int compare(student *a, student *b)
{
    if ((a->sum - b->sum) > 10 || (a->sum - b->sum) < -10)
    {
        return 0;
    }
    if ((a->a - b->a) > 5 || (a->a - b->a) < -5)
    {
        return 0;
    }
    if ((a->b - b->b) > 5 || (a->b - b->b) < -5)
    {
        return 0;
    }
    if ((a->c - b->c) > 5 || (a->c - b->c) < -5)
    {
        return 0;
    }
    return 1;
}
